<template>
  <div>
    <!-- 金税发票查询 -->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <Spin :spinning="exportLoading" tip="Loading...">
      <FilterTable
        ref="table"
        columnsRef="qjhGoldenTaxInvoiceQuery"
        :isSelectColumn="false"
        :columns="columns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'records'"
        :onColumnsChange="columns => (this.columns = columns)"
      >
        <template slot="controls">
          <multiuse-button size="small" type="primary" :click="exportHandle">导 出</multiuse-button>
        </template>
      </FilterTable>
    </Spin>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { queryList, exportExcel,exporturl } from '@/api/dealerFinance/InvoiceManage/GoldenTaxInvoiceQuery';
import { exportExcelFile } from '@/utils/index';

export default {
  name: 'GoldenTaxInvoiceQuery',
  mixins: [dictionary],

  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: queryList,
      fetchParams: {},
      formData: {},
      exportLoading: false
    };
  },

  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    // 导出
    async exportHandle() {

        let json = Object.assign({}, { CODE: 'CODE_00000236' }, this.fetchParams);
      let res = await exporturl(json);
      if (res.resultCode == 200) {
        this.$router.push('/admin/auth/oem/downloadCenter');
      }
      // await this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
      //   confirmButtonText: '下载',
      //   cancelButtonText: '取消',
      //   type: 'warning'
      // })
      //   .then(() => {
      //     this.exportLoading = true;

      //     exportExcel(this.fetchParams)
      //       .then(response => {
      //         exportExcelFile(response.data, '金税发票查询');
      //         this.exportLoading = false;
      //       })
      //       .catch(err => {
      //         console.log(err);
      //       });
      //   })
      //   .catch(() => {
      //     this.$message({
      //       type: 'info',
      //       message: '已取消'
      //     });
      //   });
    },
    createdFrom() {
      return [
        {
          type: 'TEXT_AREA',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '请输入',
          maxlength: '',
          maxRows: 2
        },
        {
          type: 'INPUT',
          label: '发票号',
          fieldName: 'invoiceNo',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '销售订单号',
          fieldName: 'orderNo',
          placeholder: '请输入'
        },
        {
          type: 'SELECT',
          label: '发票状态',
          fieldName: 'invoiceStatus',
          placeholder: '请选择',
          itemList: this.createDictList('6071')
        },

        {
          type: 'RANGE_DATE',
          label: '开票日期',
          dateType: 'exactdaterange',
          fieldName: 'invoiceBeginDate|invoiceEndDate',
          placeholder: '请选择',
          initialValue: []
        },
        {
          type: 'SELECT',
          label: '邮寄状态',
          fieldName: 'postStatus',
          placeholder: '请选择',
          itemList: this.createDictList('6090')
        },
        {
          type: 'SELECT',
          label: '动力形式',
          fieldName: 'powerType',
          placeholder: '请选择',
          itemList: this.createDictList('6008')
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '经销商代码',
          dataIndex: 'dealerCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '经销商名称',
          dataIndex: 'dealerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '销售订单号',
          dataIndex: 'orderNo',
          sorter: true,
          filter: true,
          filterType: 'input',
          align: 'center',
          width: 200
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          align: 'center',
          width: 180,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '资金类型',
          dataIndex: 'accountTypeName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '开票日期',
          dataIndex: 'invoiceDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '发票号码',
          dataIndex: 'invoiceNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '发票代码',
          dataIndex: 'invoiceCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '发票状态',
          dataIndex: 'invoiceStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6071'),
          render: props => {
            return <span>{this.createDictText(props.row.invoiceStatus, '6071')}</span>;
          }
        },
        {
          title: '邮寄状态',
          dataIndex: 'postStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6090'),
          render: props => {
            return <span>{this.createDictText(props.row.postStatus, '6090')}</span>;
          }
        },
        {
          title: '单位',
          dataIndex: 'unit',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '数量',
          dataIndex: 'num',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '单价',
          dataIndex: 'amount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '含税金额',
          dataIndex: 'includeTaxAmount',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2,
          numberFormat: true
        },
        {
          title: '税额',
          dataIndex: 'taxAmount',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2,
          numberFormat: true
        },
        {
          title: '折扣金额',
          dataIndex: 'discountAmount',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2,
          numberFormat: true
        },
        {
          title: '购买方税号',
          dataIndex: 'buyTaxNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '地址',
          dataIndex: 'address',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '电话',
          dataIndex: 'phone',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '开户行',
          dataIndex: 'openingBank',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '账号',
          dataIndex: 'account',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品代码',
          dataIndex: 'productCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品名称',
          dataIndex: 'productName',
          align: 'center',
          width: 400,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品公告号',
          dataIndex: 'noticeNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产地',
          dataIndex: 'productAddress',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '合格证号',
          dataIndex: 'certificate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '发动机号',
          dataIndex: 'engineNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '电机号',
          dataIndex: 'motorNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    }
  }
};
</script>
